package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexQueryVO;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexVO;
import com.minimalist.common.feign.client.lindi.LindiProvinceIndexFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地省级指标Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiProvinceIndexFeignClientFallbackFactory extends BaseFallbackFactory<LindiProvinceIndexFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiProvinceIndexFeignClientFallbackFactory.class);


    @Override
    public LindiProvinceIndexFeignClient create(Throwable cause) {
        return new LindiProvinceIndexFeignClient() {
            @Override
            public R<?> addProvinceIndex(LindiProvinceIndexVO indexVO) {
                logServiceUnavailable("添加省级指标", indexVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "添加省级指标失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteProvinceIndexByProvinceIndexId(Long provinceIndexId) {
                logServiceUnavailable("删除省级指标", provinceIndexId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "删除省级指标失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateProvinceIndexByProvinceIndexId(LindiProvinceIndexVO indexVO) {
                logServiceUnavailable("修改省级指标", indexVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "修改省级指标失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiProvinceIndexVO>> getPageProvinceIndexList(LindiProvinceIndexQueryVO queryVO) {
                logServiceUnavailable("分页查询省级指标列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "分页查询省级指标列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiProvinceIndexVO> getProvinceIndexByProvinceIndexId(Long provinceIndexId) {
                logServiceUnavailable("获取省级指标详情", provinceIndexId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "获取省级指标详情失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
